package com.cykj.pos.util;

import java.security.MessageDigest;

public class Md5Util {

    /**
     * @param srcSignString
     * @param key
     * @param charset
     * @return
     */
    public static String getMd5(String srcSignString, String key, String charset) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(srcSignString.getBytes(charset));

            StringBuilder result = new StringBuilder();
            byte[] temp;
            temp = md5.digest(key.getBytes(charset));
            for (byte b : temp) {
                result.append(Integer.toHexString((0x000000ff & b) | 0xffffff00).substring(6));
            }
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] a) {
        System.out
                .println(getMd5(
                        "8121kfbPlGEwrKkMa75mB$4M",
                        "123", "GBK"));
        // log.info(getMd5
        // ("CTMID=13751064472&INTECMD=A_YECXJIJDU3J4I549994KDCKD9E030LKE0DR49TIGK4O0RO4L34ODL40P4202K39K3K34",
        // "", "GBK"));
    }

}
